/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package gsb.android;

import android.app.ListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
import modele.DAO;
import modele.Medecin;

/**
 *
 * @author sio
 */
public class GsbMedecins extends ListActivity {
    
    protected void onListItemClick(ListView l, View v, int position, long id) {
        String tel = ((Medecin) l.getItemAtPosition(position)).getTelephone();
        Intent callIntent = new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse("tel:"+tel));
        startActivity(callIntent);
    }


    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.med);
        TextView label = (TextView) findViewById(R.id.label);
        Intent inter = getIntent();
        String nom = inter.getStringExtra("leDep");
        label.setText(nom);

        final List<Medecin> lesMeds = DAO.getLesMeds(nom);
        Button bouton = (Button) findViewById(R.id.buttonAffi);
        bouton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View arg0) {
                //Toast.makeText(getApplicationContext(), "", Toast.LENGTH_LONG).show();
                List<Medecin> lesMeds2 = new ArrayList<Medecin>();
                EditText rech = (EditText) findViewById(R.id.recherche);
                String recherche = rech.getText().toString();
                for (Medecin unMed : lesMeds) {
                    if (unMed.getNom().startsWith(recherche)) {
                        lesMeds2.add(unMed);
                    }
                }
                MedAdapter adapter = new MedAdapter(lesMeds2, getApplicationContext());
                setListAdapter(adapter);
            }
        });

        MedAdapter adapter = new MedAdapter(lesMeds, this);
        setListAdapter(adapter);
    }
}
